package com.intranet.sys.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.intranet.sys.dao.MenuDao;
import com.intranet.sys.domain.Menu;

@Service
public class MenuService {

	@Autowired
	private MenuDao menuDao;
	
	public List<Menu> getAllMenu(){
		return menuDao.getAllMenu();
	} 
	
	public String saveMenu(Menu menu) {
		String msg = "";
		try {
			menuDao.save(menu);
			msg = "Y";
		} catch (RuntimeException e) {
			msg = e.toString();
		}
		return msg;
	}

	public String updateMenu(Menu menu) {
		String msg = "";
		try {
			menuDao.update(menu);
			msg = "Y";
		} catch (RuntimeException e) {
			msg = e.toString();
		}
		return msg;
	}
	
	public Menu findMenu(Integer id) {
		return	menuDao.get(id);
  	}
	
	public List<Menu> findMenuByPId(int pid) {
		return menuDao.getMenuByPId(pid);
	}
	
	public String deleteMenu(Menu menu) {
		String msg = "";
		try {
			menuDao.remove(menu);
			msg = "Y";
		} catch (RuntimeException e) {
			msg = e.toString();
		}
		return msg;
	}
	
}
